import request from '../utils/request'
/**
 * 登录请求，用于用户登录
 * @param {string} mobile 手机号
 * @param {string} code 验证码
 * @returns Promise
 */
export const login = (mobile, code) => {
    return request({
        method: 'POST',
        url: '/v1_0/authorizations',
        data: {
            mobile,
            code,
        },
    })
}
/**
 * 获取用户信息
 * @returns Promise
 */
export const getUserInfo = () => {
    return request({
        url: '/v1_0/user/profile',
        method: 'get',
    })
}
/*
  获取所有的频道
*/
export const getChannels = () => {
    return request.get('/v1_0/channels')
}
/**
 * 获取文章列表
 * @param {*} params
 * @returns
 */
export const getArticles = (params) => {
    return request({
        url: '/v1_0/mp/articles',
        method: 'get',
        params,
    })
}
/**
 * 删除文章
 * @param {*} id
 * @returns
 */
export const delArticle = (id) => {
    return request({
        url: `/v1_0/mp/articles/${id}`,
        method: 'delete',
    })
}

/**
 * 发表文章
 * @param {*} 发布文章所有参数
 * @returns Promise
 */
export const publishArticleAPI = ({ draft = true, ...body }) => {
    return request({
        url: `/v1_0/mp/articles?draft=${draft}`,
        method: 'POST',
        data: body,
    })
}

/**
 * 获取文章详情信息
 * @param {*} id
 * @returns
 */
export const getArticleById = (id) => {
    return request.get(`/v1_0/mp/articles/${id}`)
}

/**
 * 修改文章的接口
 * @param {*} data
 * @param {*} draft
 * @returns
 */
export const updateArticleAPI = (data, draft) => {
    return request({
        url: `/v1_0/mp/articles/${data.id}?draft=${draft}`,
        method: 'PUT',
        data,
    });
};